<template>
  <div class="bid-info">
    <div class="info-div">
      <div class="info-title">
        <span>标书附件下载</span>
      </div>
      <div class="info-text w50">
          <span>招标书文件下载：</span>
          <span class="text-value">
            <a href="javascript:;" @click="downloadFile(infoData.tenderDemandPath,infoData.tenderDemandName)" class="download_color">{{infoData.tenderDemandName}}</a>
          </span>
      </div>
      <div class="info-text w50">
          <span>招标需求文件下载：</span>
        <span class="text-value">
          <a href="javascript:;" @click="downloadFile(infoData.tenderFilePath,infoData.tenderFileName)" class="download_color">{{infoData.tenderFileName}}</a>
        </span>
      </div>
    </div>
    <div class="info-div">
      <div class="info-title">
        <span>保证金缴费凭证附件</span>
      </div>
      <div v-if="isNeedBond===0">不需要缴纳保证金</div>
      <div v-if="isNeedBond===3">
        <div class="info-text w50">
          <el-upload class="upload-file" ref="upload" :action="this.lib.config.host.system + '/common/fileupload/upload'" :data=fileData
                    :limit="1" :on-success="res=>{uploadSuccess(res,'cashDepositPayFileId')}">
            <el-button slot="trigger" type="primary">选取文件</el-button>
          </el-upload>
        </div>
        <div class="info-text w50">
          <el-button type="primary" @click="uploadBondPay">提交</el-button>
        </div>
      </div>
      <div v-if="isNeedBond===1">
        <span class="text-value">
          <a href="javascript:;" @click="downloadFile(bidVendor.bondPayFilePath,bidVendor.bondPayFileName)" class="download_color">{{bidVendor.bondPayFileName}}</a>
        </span>
      </div>

    </div>
  </div>
</template>
<script>
  import qs from 'qs';
  export default {
    props:['stepData'],
    data() {
      return {
        // 定义附件的业务模块和业务动作
        fileData: {
          busAction: "TENDER_UP_PLOAD_CASH_DEPPAY",
          tableName: "BID_VENDORS",
          tableId: this.$route.query.id
        },
        infoData:{},
        bidVendor:{},
        ruleForm:{
          cashDepositPayFileId:''
        }
      };
    },
    computed:{
        isNeedBond(){
            return this.stepData.bidMainDto.isNeedBond===0?0:this.stepData.bidVendor.bondPayStatus;
        }
    },   
    mounted(){
      this.infoData=this.stepData.bidMainDto;
      this.bidVendor=this.stepData.bidVendor;
    },
    methods: {      
      uploadBondPay(type){
        let data={
          cashDepositPayFileId:this.ruleForm.cashDepositPayFileId
        }
        this.axios.post(`${this.lib.config.host.bidtender}/bidmgt/tender/uploadCashDepPay/${this.$route.query.id}`,qs.stringify(data)).then((res) => {
          if(res.data.success){
            this.$message.success('上传保证金成功！');
        }}).catch(function (error) {
            console.log(error);
        });
      },
      uploadSuccess: function (response,type) {
        //附件上传成功回调
        this.ruleForm[type] = response.id;
      },
      // 下载附件
      download(filePath, fileName) {
        this.downloadFile(filePath, fileName);
      }
    }
  }

</script>
